package com.hspedu.newData.dmsxl.滑动窗口;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC643子数组最大平均数Ⅰ {

    public double findMaxAverage(int[] nums, int k) {

        int slow = 0;
        int fast = k-1;

        double sum = 0;
        for (int i = 0; i < k; i++) {
            sum += nums[i];
        }

        double max = sum/k;
        while(fast<nums.length-1){
            sum += nums[++fast];
            sum -= nums[slow++];
            max = Math.max(max,sum/k);
        }
        return max;
    }


    @Test
    public void test() {
        // 测试代码

        findMaxAverage(new int[]{1,12,-5,-6,50,3},4);
    }

}
